<?php

/**
 * This is the model class for table "rx".
 *
 * The followings are the available columns in table 'rx':
 * @property integer $id
 * @property integer $pd_od
 * @property integer $pd_os
 * @property integer $pd
 * @property string $tint
 * @property string $lens_material
 * @property string $lens_design
 * @property string $instruction
 * @property string $segment_height
 * @property integer $personalinfo_id
 * @property integer $inventory_id
 * @property integer $employee_id
 *
 * The followings are the available model relations:
 * @property ContactRxLeft[] $contactRxLefts
 * @property ContactRxRight[] $contactRxRights
 * @property ExternalExam[] $externalExams
 * @property Fundus[] $funduses
 * @property Keratometry[] $keratometries
 * @property Motility[] $motilities
 * @property Others[] $others
 * @property PhoriaDistance[] $phoriaDistances
 * @property PhoriaNear[] $phoriaNears
 * @property Pupil[] $pupils
 * @property RefractionOd[] $refractionOds
 * @property RefractionOs[] $refractionOses
 * @property Employee $employee
 * @property Inventory $inventory
 * @property PersonalInformation $personalinfo
 * @property SiltLampExam[] $siltLampExams
 * @property SpectacleRxDist[] $spectacleRxDists
 * @property SpectacleRxNear[] $spectacleRxNears
 * @property Tonometry[] $tonometries
 * @property VisualAcuityDist[] $visualAcuityDists
 * @property VisualAcuityNear[] $visualAcuityNears
 */
class Rx extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Rx the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'rx';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('employee_id', 'required'),
			array('pd_od, pd_os, pd, personalinfo_id, inventory_id, employee_id', 'numerical', 'integerOnly'=>true),
			array('tint', 'length', 'max'=>15),
			array('lens_material, lens_design', 'length', 'max'=>30),
			array('instruction', 'length', 'max'=>45),
			array('segment_height', 'length', 'max'=>6),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, pd_od, pd_os, pd, tint, lens_material, lens_design, instruction, segment_height, personalinfo_id, inventory_id, employee_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'contactRxLefts' => array(self::HAS_MANY, 'ContactRxLeft', 'rx_id'),
			'contactRxRights' => array(self::HAS_MANY, 'ContactRxRight', 'rx_id'),
			'externalExams' => array(self::HAS_MANY, 'ExternalExam', 'rx_id'),
			'funduses' => array(self::HAS_MANY, 'Fundus', 'rx_id'),
			'keratometries' => array(self::HAS_MANY, 'Keratometry', 'rx_id'),
			'motilities' => array(self::HAS_MANY, 'Motility', 'rx_id'),
			'others' => array(self::HAS_MANY, 'Others', 'rx_id'),
			'phoriaDistances' => array(self::HAS_MANY, 'PhoriaDistance', 'rx_id'),
			'phoriaNears' => array(self::HAS_MANY, 'PhoriaNear', 'rx_id'),
			'pupils' => array(self::HAS_MANY, 'Pupil', 'rx_id'),
			'refractionOds' => array(self::HAS_MANY, 'RefractionOd', 'rx_id'),
			'refractionOses' => array(self::HAS_MANY, 'RefractionOs', 'rx_id'),
			'employee' => array(self::BELONGS_TO, 'Employee', 'employee_id'),
			'inventory' => array(self::BELONGS_TO, 'Inventory', 'inventory_id'),
			'personalinfo' => array(self::BELONGS_TO, 'PersonalInformation', 'personalinfo_id'),
			'siltLampExams' => array(self::HAS_MANY, 'SiltLampExam', 'rx_id'),
			'spectacleRxDists' => array(self::HAS_MANY, 'SpectacleRxDist', 'rx_id'),
			'spectacleRxNears' => array(self::HAS_MANY, 'SpectacleRxNear', 'rx_id'),
			'tonometries' => array(self::HAS_MANY, 'Tonometry', 'rx_id'),
			'visualAcuityDists' => array(self::HAS_MANY, 'VisualAcuityDist', 'rx_id'),
			'visualAcuityNears' => array(self::HAS_MANY, 'VisualAcuityNear', 'rx_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'pd_od' => 'Pd Od',
			'pd_os' => 'Pd Os',
			'pd' => 'Pd',
			'tint' => 'Tint',
			'lens_material' => 'Lens Material',
			'lens_design' => 'Lens Design',
			'instruction' => 'Instruction',
			'segment_height' => 'Segment Height',
			'personalinfo_id' => 'Patient First Name',
			'personalinfo' => 'Patient Last Name',
			'inventory_id' => 'Product Used',
			'employee_id' => 'Employee Name',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('pd_od',$this->pd_od);
		$criteria->compare('pd_os',$this->pd_os);
		$criteria->compare('pd',$this->pd);
		$criteria->compare('tint',$this->tint,true);
		$criteria->compare('lens_material',$this->lens_material,true);
		$criteria->compare('lens_design',$this->lens_design,true);
		$criteria->compare('instruction',$this->instruction,true);
		$criteria->compare('segment_height',$this->segment_height,true);
		$criteria->compare('personalinfo_id',$this->personalinfo_id);
		$criteria->compare('inventory_id',$this->inventory_id);
		$criteria->compare('employee_id',$this->employee_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}